package com.example.java_chatroom_redis_rabbitmq.utils;

import com.example.java_chatroom_redis_rabbitmq.component.RabbitMessageQueueListener;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.Executor;

@Component
public class ThreadPoolUtil {
    @Resource(name = "taskExecutor")
    private Executor taskExecutor;

    @Autowired
    private SimpleMessageListenerContainer simpleMessageListenerContainer;

    @Autowired
    private RabbitMessageQueueListener rabbitMessageQueueListener;

    @PostConstruct
    public void init() {
        taskExecutor.execute(() -> {
            simpleMessageListenerContainer.setMessageListener(rabbitMessageQueueListener);
            simpleMessageListenerContainer.addQueueNames("message.queue");
        });
    }
}
